package com.tled.zyf.cookie;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/cookieDemo2")
public class CookieDemo_02 extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取所有 cookie
		Cookie[] cs = request.getCookies();
		if (cs != null && cs.length > 0) {
			for (Cookie cookie : cs) {
				String name = cookie.getName();
				String value = cookie.getValue();
				System.out.println(name + ":" + value);
			}
		}
	}
}
